Telegram Group & Telegram Channel
Что выведет этот код на Python?


def append_to(element, to=[]):
to.append(element)
return to

print(append_to(1))
print(append_to(2))
print(append_to(3, []))
print(append_to(4))


🔢 Варианты ответа:

A)

[2]
[3]
[4]


B)

[1, 2]
[3]
[1, 2, 4]


C)

[1, 2]
[1, 2, 3]
[1, 2, 3, 4]


D)

[1, 2]
[3]
[4]


Правильный ответ: B

💡 Почему?

В Python дефолтные аргументы вычисляются один раз — при определении функции.
Список
to=[] сохраняется и используется повторно, если явно не передан другой.
Поэтому
append_to(1), append_to(2) и append_to(4) работают с одним и тем же списком.



tg-me.com/python_job_interview/1070
Create:
Last Update:

Что выведет этот код на Python?


def append_to(element, to=[]):
to.append(element)
return to

print(append_to(1))
print(append_to(2))
print(append_to(3, []))
print(append_to(4))


🔢 Варианты ответа:

A)

[2]
[3]
[4]


B)

[1, 2]
[3]
[1, 2, 4]


C)

[1, 2]
[1, 2, 3]
[1, 2, 3, 4]


D)

[1, 2]
[3]
[4]


Правильный ответ: B

💡 Почему?

В Python дефолтные аргументы вычисляются один раз — при определении функции.
Список
to=[] сохраняется и используется повторно, если явно не передан другой.
Поэтому
append_to(1), append_to(2) и append_to(4) работают с одним и тем же списком.

BY Python вопросы с собеседований


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/python_job_interview/1070

View MORE
Open in Telegram


Python вопросы с собеседований Telegram | DID YOU KNOW?

Date: |

Start with a fresh view of investing strategy. The combination of risks and fads this quarter looks to be topping. That means the future is ready to move in.Likely, there will not be a wholesale shift. Company actions will aim to benefit from economic growth, inflationary pressures and a return of market-determined interest rates. In turn, all of that should drive the stock market and investment returns higher.

A project of our size needs at least a few hundred million dollars per year to keep going,” Mr. Durov wrote in his public channel on Telegram late last year. “While doing that, we will remain independent and stay true to our values, redefining how a tech company should operate.

Python вопросы с собеседований from id


Telegram Python вопросы с собеседований
FROM USA